package com.qcby.util;

import com.qcby.entity.Question;
import org.json.JSONArray;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class JsonParseOptions {

    public List<Question> getOptions(List<Question>list) {
        for(int i = 0;i<list.size();i++){
            List<String> optionsList = new ArrayList<>();
            String options = list.get(i).getOptions();
            if(options == null) continue;
            JSONArray jsonArray = new JSONArray(options);
            for(int j = 0;j<jsonArray.length();j++){
                optionsList.add(jsonArray.getString(j));
            }
            list.get(i).setOptionsList(new ArrayList<>(optionsList));
        }
        return list;
    }
}
